package edu.ycxy.poetry.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.ycxy.poetry.entity.DjInfo;
import edu.ycxy.poetry.vo.AddDjVo;
import edu.ycxy.poetry.vo.UpdateDjVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author @xin
 * @createDate 2022/3/14
 * @Description
 */
@Repository
public interface DjInfoMapper extends BaseMapper<DjInfo> {

    //根据id查询详细的内容
    @Select("select * from vab_dj_info where aid=#{aid}")
    List<DjInfo> selectList(Integer aid);

    //根据aid查询出来的主标题,获取每个数据的次标题
    @Select("select * from vab_dj_info where zjtype=#{id}")
    List<DjInfo> selectLisTById(Integer id);


    //根据古籍的章节目录的id查询该目录里面的详细内容
    @Select("select * from vab_dj_info where id=#{id}")
    DjInfo findContentById(Integer id);

    //新增古籍章节
    @Insert("insert into vab_dj_info(aid,title,body,info) values ((select id from vab_dj_list where title=#{title}),#{djTitle},#{body},#{body})")
    Integer addDjInfo(AddDjVo addDjVo);

    // 模糊查询
    @Select("select * from vab_dj_info where title like CONCAT('%',#{title},'%')")
    List<DjInfo> findFuzzy(String title);

    @Delete("delete from vab_dj_info where id=#{id}")
    Integer deleteDjInfoById(Integer id);

    @Update("update vab_dj_info set title=#{title},body=#{body},info=#{body} where id=#{id}")
    Integer updateDjInfo(UpdateDjVo updateDjVo);

    //根据名字查询章节
    @Select("select * from vab_dj_info where title=#{title}")
    DjInfo findByTitle(String title);
}
